package com.sccc.actions;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.sccc.bizImpl.UserManeger;

public class AjaxAction extends ActionSupport {
      //检查用户名是否存在Action
	String uName;
	
	public String getuName() {
		return uName;
	}

	public void setuName(String uName) {
		this.uName = uName;
	}

	@Override
	public String execute() throws Exception {
		
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();

			request.setCharacterEncoding("UTF-8");
	        response.setContentType("text/xml;charset=UTF-8");
	        response.setHeader("Cache-Control", "no-cache");
	        PrintWriter out = response.getWriter();
	        out.println("<response>");
	 //实例化一个所有方法的对象       
	        UserManeger userManeger = new UserManeger();
	        boolean isExists;
	        isExists = userManeger.findByUsername(getuName());
	        
	        
	        
	       if(isExists){
	              out.println("<res>" + "用户名已存在,换个用户名吧 !" + "</res>");
	       }else{
	              out.println("<res></res>");
	       }
	       
	        out.println("</response>");
	        out.close();
		
		return null;
	}


}
